/**
 * 
 */
package com.tjtt.tdm.flow.service.impl;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;

import com.tjtt.tdm.base.PageResult;
import com.tjtt.tdm.exception.DaoException;
import com.tjtt.tdm.exception.ServiceException;
import com.tjtt.tdm.flow.bean.FlowDetailed;
import com.tjtt.tdm.flow.bean.FlowTask;
import com.tjtt.tdm.flow.bean.Flowtype;
import com.tjtt.tdm.base.PubMethod;
import com.tjtt.tdm.flow.dao.IWorkflowDao;
import com.tjtt.tdm.flow.service.IWorkflowService;

/**
 * @author 张海娜
 *
 */
public class WorkflowServiceImpl  implements IWorkflowService{
	private IWorkflowDao workflowDao;

	public PageResult queryWaitWorkListNew(Map<String, String> filterMap) {
		return workflowDao.queryWaitWorkListNew(filterMap);
	}
	
	public PageResult queryDaiqian(Map<String, String> filterMap) {
		return workflowDao.queryDaiqian(filterMap);
	}
	
	public PageResult queryYiban(Map<String, String> filterMap) {
		return workflowDao.queryYiban(filterMap);
	}
	
	@Override
	public PageResult queryBanjie(Map<String, String> filterMap) {
		return workflowDao.queryBanjie(filterMap);
	}

	@Override
	public PageResult queryFlowByState(Map<String, String> filterMap) {
		return workflowDao.queryFlowByState(filterMap);
	}

	@Override
	public PageResult queryJinxing(Map<String, String> filterMap) {
		return workflowDao.queryJinxing(filterMap);
	}

	@Override
	public PageResult queryCaosong(Map<String, String> filterMap) {
		return workflowDao.queryCaosong(filterMap);
	}

	@Override
public PageResult queryQingqiu(Map<String, String> filterMap) {
		return workflowDao.queryQingqiu(filterMap);
	}

	@Override
	public PageResult queryWancheng(Map<String, String> filterMap) {
		return workflowDao.queryWancheng(filterMap);
	}

	public PageResult queryMyRequestExec(Map<String, String> filterMap){
		return workflowDao.queryMyRequestExec(filterMap);
	}
	
	public PageResult queryReportlist(Map<String, String> filterMap) {
		return workflowDao.queryReportlist(filterMap);
	}
	
	public PageResult queryWaitWorkListNewMyTask(Map<String, String> filterMap) {
		return workflowDao.queryWaitWorkListNewMyTask(filterMap);
	}

	
	public PageResult queryWaitExpWorkListNew(Map<String, String> filterMap) {
		return workflowDao.queryWaitExpWorkListNew(filterMap);
	}
	
	/**
	 * 我的代办试验显示到jqrid
	 * @return
	 * @throws IOException
	 * @throws ServiceException String
	 * @author 张海娜
	 * @date 2013-2-22 下午03:53:34
	 */
	public PageResult queryWaitWorkList(Map<String, String> filterMap) {
		return this.workflowDao.queryWaitWorkList(filterMap);
	}
	
	public PageResult queryXieZuoWaitWorkListNew(Map<String, String> filterMap) {
		return this.workflowDao.queryXieZuoWaitWorkListNew(filterMap);
	}
	
	public PageResult queryDaiQianWaitWorkListNew(Map<String, String> filterMap) {
		return this.workflowDao.queryDaiQianWaitWorkListNew(filterMap);
	}

	public void updateQianShou(String ids, String userId, String userName) {
		this.workflowDao.updateQianShou(ids, userId, userName);
	}
	
	
	public String getStates(long id) {
		List statelist = workflowDao.getFlowStates(id);
		String states = "";
		for(int i = 0 ;i<statelist.size();i++)
		{
			if (i==0)
			{
				states += statelist.get(i).toString();
			}
			else
			{
				states += ","+statelist.get(i).toString();
			}
		}
		return states;
	}

	public String getFlowfilepath(String id) {
		return workflowDao.getFlowfilepath(id);
	}

	/**
	 * 我的已办试验显示到jqrid
	 * @return
	 * @throws IOException
	 * @throws ServiceException String
	 * @author 张海娜
	 * @date 2013-2-22 下午03:53:34
	 */
	public PageResult queryDoneWorkList(Map<String, String> filterMap) {
		return this.workflowDao.queryDoneWorkList(filterMap);
	}

	/**
	 * 查看全部流程操作详细
	 * @return
	 * @throws IOException
	 * @throws ServiceException String
	 * @author 张海娜
	 * @date 2013-3-12 下午02:23:26
	 */
	public PageResult queryWorkDetailList(String id,Map<String, String> filterMap) {
		return this.workflowDao.queryWorkDetailList(id,filterMap);
	}

	/**
	 * 查看某一个流程的操作详细
	 * @return
	 * @throws IOException
	 * @throws ServiceException String
	 * @author 张海娜
	 * @date 2013-3-12 下午02:23:26
	 */
	public PageResult queryWorkDetailList2(String stateid, String id,
			Map<String, String> filterMap) {
		return this.workflowDao.queryWorkDetailList2(stateid,id,filterMap);
	}

	/**
	 * 我的理化中心代办试验显示到jqrid
	 * @return
	 * @throws IOException
	 * @throws ServiceException String
	 * @author 张海娜
	 * @date 2013-2-22 下午03:53:34
	 */
	public PageResult queryRationalizeWaitWorkList(Map<String, String> filterMap) {
		return this.workflowDao.queryRationalizeWaitWorkList(filterMap);
	}


	//我的计量中心待办列表显示
	public PageResult queryWaitWorkListJL(Map<String, String> filterMap) {
		return this.workflowDao.queryWaitWorkListJL(filterMap);
	}
	public IWorkflowDao getWorkflowDao() {
		return workflowDao;
	}

	public void setWorkflowDao(IWorkflowDao workflowDao) {
		this.workflowDao = workflowDao;
	}

	
	public String getJianyanstate(String id,String state){
		return workflowDao.getJianyanstate(id,state);
	}

	public List getTestCenterFlowDetailList(long id,long instanceid)
	{
		return workflowDao.getTestCenterFlowDetailList(id, instanceid);
	}
	
	public int getUndoWorkCount(Map<String, String> filterMap) {
		// TODO Auto-generated method stub
		return workflowDao.getUndoWorkCount(filterMap);
	}

	public PageResult queryWaitWorkListJLTest(Map<String, String> filterMap) {
		return workflowDao.queryWaitWorkListJLTest(filterMap);
	}


	
	public PageResult queryWaitWorkDetailList(Map<String, String> filterMap) {
		return workflowDao.queryWaitWorkDetailList(filterMap);
	}
    /**
    * 
    *方法描述：查看试验中心流程的操作详细记录
    *@author: wangxd
    *@date： 2013-5-28 下午06:57:21
    *@param filterMap
    *@return
    */
	public PageResult queryTestCenterWaitWorkDetailList(Map<String, String> filterMap)
	{
		return workflowDao.queryTestCenterWaitWorkDetailList(filterMap);
	}
	
	public FlowTask getFlowTaskById(String id) {
		// TODO Auto-generated method stub
		return workflowDao.getFlowTaskById(id);
	}
	
	public void updateFlowTask(String ids, String state) {
		// TODO Auto-generated method stub
		String id[] = ids.split(",");
		for(int i=0; i<id.length; i++){
			Object[] values =null;
			FlowTask flowTask =null;
			Long flowTypeId = null;

			flowTask = workflowDao.getFlowTaskById(id[i]);
			flowTypeId = flowTask.getFlowTypeId();
			flowTask.setState(Long.parseLong(state));
			workflowDao.updateFlowTask(flowTask);
			
//			String userId = ServletActionContext.getRequest().getSession().getAttribute("TDM_USER_ID").toString();
//			String userNm = ServletActionContext.getRequest().getSession().getAttribute("username").toString();
//			FlowDetailed flowDetailed = new FlowDetailed();
//			flowDetailed.setFlowTaskId(Long.parseLong(values[2].toString()));
//			flowDetailed.setOperatorperson(userNm);
//			flowDetailed.setOperatortime(new Timestamp(System.currentTimeMillis()));
//			if(state.equals("2")){			//挂起
//				flowDetailed.setStatusbefore("");
//				flowDetailed.setStatusafter("挂起");
//			}else if(state.equals("3")){	//终止
//				flowDetailed.setStatusbefore("");
//				flowDetailed.setStatusafter("终止");
//			}else if(state.equals("0")){	//恢复
//				flowDetailed.setStatusbefore("挂起");//只能从挂起状态恢复
//				flowDetailed.setStatusafter("恢复");
//			}
//			flowDetailed.setStatusafterid("end");
//			flowDetailed.setFlowTypeId(flowTypeId);
//			flowDetailed.setOperatorpersonId(Long.parseLong(userId));
//			workflowDao.saveFlowDetailed(flowDetailed);
		}
	}
	/**
	 * 
	 *方法描述：根据操作人的操作记录查询流程的当前状态
	 *@author: wangxd
	 *@date： 2013-6-7 上午09:34:26
	 *@param instanceId
	 *@param flowTypeId
	 *@param flowStateId
	 *@param flowStateId1
	 *@return
	 */
	  public List<FlowTask> queryTaskByIdName(Long instanceId,Long flowTypeId) 
	  {
		  return workflowDao.queryTaskByIdName(instanceId, flowTypeId);
	  }

	
	public PageResult queryFaQiWorkExec(Map<String, String> filterMap) {
		return workflowDao.queryFaQiWorkExec(filterMap);
	}

	
	public List<Flowtype> getFlowtypeList() {
		return workflowDao.getFlowtypeList();
	}
	
	
	public List getStandardList() {
		return workflowDao.getStandardList();
	}

	
	public List getFlowDetailList(long id) {
		return workflowDao.getFlowDetailList(id);
	}

	
	public void changeFlowTaskUngentExec(String id) {
		workflowDao.changeFlowTaskUngentExec(id);
		workflowDao.changeCftdmUngentExec(id);
	}

	
	public PageResult queryRationalizeDataList(Map<String, String> filterMap) {
		return this.workflowDao.queryRationalizeDataList(filterMap);
	}

	
	public List findRationData(Map filterMap) {
		return this.workflowDao.findRationData(filterMap);
	}

	
	public PageResult queryRationalizeDataZongList(Map<String, String> filterMap) {
		return this.workflowDao.queryRationalizeDataZongList(filterMap);
	}
	
	/*
	 * 查询流程状态及数量   一般、加急、延期
	 * wxj
	 */
	public List queryFlowtaskType(Map filterMap){
		return workflowDao.queryFlowtaskType(filterMap);
	}

	public PageResult queryYiqigllist(Map<String, String> filterMap){
		return workflowDao.queryYiqigllist(filterMap);
	}
}
